package ext.tianma.doc.util;

import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import ext.tianma.util.PropertiesUtil;
/**
 * 获得受控PDF图纸编号
 * @author deng
 *
 */
@Controller
@RequestMapping({ "/GetControlDocumentNum" })
public class GetControlDocumentNum {
	private static String configFilePath = "codebase" + File.separator + "ext"
			+ File.separator + "tianma" + File.separator + "cfg"
			+ File.separator + "TianmaPro.properties";
	@RequestMapping(value = "/getControlDocumentNum", method = {
			RequestMethod.POST, RequestMethod.GET })
	public void getControlDocumentNum(HttpServletResponse response) throws Exception {
		boolean enforce = wt.session.SessionServerHelper.manager
				.setAccessEnforced(false);
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");
		PropertiesUtil ut = new PropertiesUtil(configFilePath);
		String ControlDocumentNums = ut.getValueByKey("DCC.ControlDocumentNum");
		try {
			String result = "";
			JSONObject ob = new JSONObject();
			List<String> list = new ArrayList<String>();
			if(!"".equals(ControlDocumentNums) && ControlDocumentNums != null) {
				String[] ControlDocumentNum = ControlDocumentNums.split(";");
				for(int i =0; i<ControlDocumentNum.length; i++) {
					list.add(ControlDocumentNum[i]);
				}
			}
			if(list.size()>0) {
				ob.put("status", "success");
				ob.put("message", "查询成功!");
				ob.put("data", list);
			}else {
				ob.put("status", "false");
				ob.put("message", "未查到！");
			}
			result = ob.toString();
			out.print(result);
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			wt.session.SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
}
